# -*- coding: utf-8 -*-
import requests

# 网址和cookie（字典格式）
url = 'https://weibo.com/a/hot/realtime'
headers = {'cookie': 'SUB=_2AkMpI-kGf8NxqwJRmf0Wy23hZYh3zwjEieKffxjdJRMxHRl-yT9jqnVctRB6AqPH6Vd_EAxhArk3EJ6KZ5tSTy2q3MqM; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WWTyeHjirmFi3w3vWh5Cr5w; SINAGLOBAL=6568045640678.919.1585883545730; UOR=,,bj.weather.com.cn; ULV=1588498439165:2:1:1:6169890101855.666.1588498439142:1585883546655; Ugrow-G0=1ac418838b431e81ff2d99457147068c; TC-V5-G0=799b73639653e51a6d82fb007f218b2f; WBStorage=42212210b087ca50|undefined'}
# 开始抓取数据
try:
    r = requests.get(url, headers=headers)
    print(r)
except:
    print('请求失败')

# 写入文本格式数据
with open('本地网页/微博.html', 'w', encoding='utf8') as f:
    f.write(r.text)